Skip to content

Conversation

@martinResearch
Copy link

draft PR to solve #58
I wrote this before realizing there was another PR to fix the same issue here

Note that I had to use kwargs["default"] = field.default for the test to pass. I did not read the code in enough detail to have confidence that it is the right fix.

kwargs["required"] = True
else:
kwargs["default"] = MISSING
kwargs["default"] = field.default
Copy link
Contributor

@jcal-15 jcal-15 Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep the default as MISSING so that the dataclass's initialization handles the default value. This is needed so default_factory can work correctly.

Also, doing it this way makes the initialization consistent with initializing the dataclass outside of the argparse_dataclass package

Comment on lines +64 to +67
params = argpument_parser.parse_args([])
print(params)
self.assertEqual(42, params.x)
self.assertEqual(False, params.y)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse_args returns a namespace object not a Opt so it is not expected to have the defaults set.

@martinResearch martinResearch closed this by deleting the head repository Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants